﻿using LuckyShell.ShellValues;

namespace LuckyShell.Commands;

public class StaticCommand
{
    public Command FromNameToCommand(string name, List<ShellValue> values)
    {
        if (string.IsNullOrEmpty(name)) throw new Exception("Command is NullOrEmpty");
        if (name == "Static") throw new Exception("Command cannot say Static");
        var type = GetType();
        var s = type.FullName?.Replace("Static", name);
        if (string.IsNullOrEmpty(s)) throw new Exception("Command Type is Error");
        var t = Type.GetType(s);
        if (t == null) throw new Exception($"Not Found Command: {name}");
        if (Activator.CreateInstance(t, values) is not Command c)
            throw new Exception("Command Reflection Error");
        return c;
    }
}